﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Utilities.Configuration;
using Services.GetData.Entity;
using EnglishStudy.Service;
using GuideServices.Service.IService;
using Utilities.Dictionary;


namespace GuideServices.Service
{
    public class WebService : BaseWebService, IWebService
    {
        public WebService()
        {
        }

        public WebService(IRestfulHttpClient restClient)
            : base(restClient)
        {
        }
        protected override Uri GetBaseUri()
        {
            return new Uri(ApplicationContext.Instance.GetValue("ApiEnglish"));
        }
        public async Task<User> Login(string useName, string password)
        {
            try
            {
                string serviceurl = "user/login";
                IDictionary<string, string> param = new Dictionary<string, string>();
                param.Add("Username", useName.Trim());
                param.Add("password", password.Trim());

                User login = await DoGetJonAsync<User>(serviceurl, param);
                return login;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return null;

        }


        public async Task<User> SignUp(RequestUser user)
        {
            try
            {
                string serviceurl = "user/signup";

                IDictionary<string, string> requestParams = ObjectUtils.CreateDictionary(user);
                User signup = await DoGetJonAsync<User>(serviceurl, requestParams);
                return signup;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return null;
        }

        public async Task<TypeName> GetAllType(string userName, string etoken)
        {
            try
            {
                string serviceUrl = "Type/GetAllType";
                TypeName typeName = await DoGetJonAsync<TypeName>(serviceUrl, null,userName,etoken);
                return typeName;
            }
            catch(Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return null;
        }
    }
}